<?php
header("content-type:text/html;charset=utf-8");

class Admin_Order_Controller extends Base_Controller {

    public function action_index()
    {  
        $orderStatus = Config::get('customer.order_status');
        $n = Input::get('n',null);  //关键字
        $p = Input::get('p',null);  //车牌号
        $m = Input::get('m')!=0 ? Input::get('m') : '';  //预约状态
        $su = array('n'=>$n,'p'=>$p,'m'=>$m);
        $data1['o.shopname'] = array('like','%'.$n.'%');
        $data1['o.username'] = array('like','%'.$n.'%');
        $data1['o.f_id'] = array('like','%'.$n.'%');
        $data1['o.phone'] = array('like','%'.$n.'%');
        $data['o.platenumber'] = array('like','%'.$p.'%');
        $data['o.status'] = array('like','%'.$m.'%');     
        $res = DB::table('orders as o')
                ->where('o.status','!=',-1)
                ->where(function($query) use($data1) {
                foreach($data1 as $column => $val)
                {
                  $query->or_where($column, $val[0], $val[1]);
                }
                })
                ->where(function($query) use($data) {
                foreach($data as $column => $val)
                {
                  $query->where($column, $val[0], $val[1]);
                }
                })->paginate(10);
           
        return View::make('admin/order',array('res'=>$res,'su'=>$su,'os'=>$orderStatus));
    }


    public function action_dele()
    {
        $id = Input::get('id');
        $dele = -1;
        $str = DB::table('orders')->where('id','=',$id)->update(array('status'=>$dele));
        if($str){
            $data = array(
                'code'=>'200',
                'msg'=>'删除成功'
                );
        }else{
            $data = array(
                'code'=>'400',
                'msg'=>'删除失败'
                );
        }
        return json_encode($data);


    }



    public function action_change()
    {
        $orderStatus = Config::get('customer.order_changes');
        $id = Input::get('id');
        $str = DB::table('orders')->where('id','=',$id)->first();
        return View::make('admin/orderchange',array('str'=>$str,'os'=>$orderStatus));
    }


    public function action_orderdochange()
    {
        $id = Input::get('thisid');
        $shopname = Input::get('shopname','');
        $f_id = Input::get('f_id','');
        $platenumber = Input::get('platenumber','');
        $username = Input::get('username','');
        $phone = Input::get('phone','');
        $firm_orders = Input::get('firm_orders','');
        $timeapp = Input::get('timeapp','');
        $servicetime = Input::get('servicetime','');
        $status = Input::get('status','');
        $str = DB::table('orders')->where('id','=',$id)->update(array('shopname'=>$shopname,'f_id'=>$f_id,'platenumber'=>$platenumber,'username'=>$username,'phone'=>$phone,'firm_orders'=>$firm_orders,'timeapp'=>$timeapp,'servicetime'=>$servicetime,'status'=>$status));
        if($str){
            return View::make('jump/jumpto',array('msg'=>'订单修改成功','url'=>'index','time'=>2));
        }else{
            return View::make('jump/error',array('msg'=>'订单修改失败','time'=>5));
        }

    }


    public function action_detail()
    {

        $id = Input::get('id');
        $orderStatus = Config::get('customer.order_changes');   
        $str = DB::table('orders')->where('id','=',$id)->first();
        return View::make('admin/orderdetail',array('str'=>$str,'orderStatus'=>$orderStatus)); 
    }





























}